#!/usr/bin/env node
const createJson = require('./createJson.js');
const config = require('./config.json');
const path = require('path');
const process = require('process');
const rootPath = process.cwd();
require('shelljs/global');

const prompt = require('./prompt.js');
const produceFrame = require('./produceFrame.js');
const targetPath = path.resolve(rootPath, config.frame.tempDir, '../');

module.exports = function createCombJson (combJsonOpt) {
    const jsonPath = path.resolve(targetPath, 'comb.json');
    return new Promise ((resolve, reject) => {
        prompt('是否指定框架版本号？(y/n)', /[n|y]/).then((answer) => {
            if ('y' === answer) {
                prompt('输入框架版本号(1.0.0)',/^\d+\.\d+\.\d+$/).then((res) => {
                    combJsonOpt.version = res;
                    createJson(combJsonOpt, jsonPath).then((data) => {
                        echo('comb.json创建成功'.green);
                        resolve(data);
                    });
                });
            } else {
                createJson(combJsonOpt, jsonPath).then((data) => {
                    echo('comb.json创建成功'.green);
                    resolve(data);
                });
            }
        });
    });
};
